﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YouFoodIncBDD;
using YouFoodIncWeb.Models;

namespace YouFoodIncWeb.Controllers
{
    public class CategoryController : Controller
    {
        //
        // GET: /Category/
        YouFoodIncBDDEntities context;

        public CategoryController()
        {
            context = new YouFoodIncBDDEntities();
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult CreateCategory(FoodsCategory model)
        {
            if (ModelState.IsValid)
            {
                FoodsCategory category = new FoodsCategory();
                category = model;
                context.FoodsCategories.AddObject(category);
                context.SaveChanges();
            }
            return View(model);
        }

        [HttpPost]
        public ActionResult CreateSubCategory(FoodsSubCategory model)
        {
            if (ModelState.IsValid)
            {
                FoodsSubCategory subCategory = new FoodsSubCategory();
                subCategory = model;
                context.FoodsSubCategories.AddObject(subCategory);
                context.SaveChanges();
            }
            return View(model);
        }

    }
}
